<template>
	<view class="columnbox wdh-100">
		<image src="/static/img/logo.png" mode="aspectFill" class="logo"></image>
		<view class="rowbox name">袋鼠会员通</view>
		<button class="rowbox log-btn def-bgcol" withCredentials="true" @click="getUserProfile">立即登录</button>
		<view class="rowbox no-log">暂不登录</view>
		<label class="rowbox wdh-100 radio-box" @click="agreeflag=!agreeflag">
			<radio color="#00ab47" style="transform: scale(0.7);" value="r1" :checked="agreeflag" />
			我已阅读并同意
			<navigator url="">
				<text class="def-col">《用户协议》</text>
			</navigator> 、
			<navigator url="">
				<text class="def-col">《隐私协议》</text>
			</navigator>
		</label>
		<u-popup @close="phoneshow=false" :show="phoneshow" :duration="100" round="10rpx" mode="center">
			<view class="slot-content columnbox">
				<!-- <view class="loginfobox rowbox spb">
					<view class="title">头像</view>
					<view class="rowbox">
						<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
						</button>
						<image v-if="avatarUrl==''" class="avatar" src="/static/img/tx.png"> </image>
						<image v-else class="avatar" :src="avatarUrl"></image>
					</view>
				</view> -->
				<image src="/static/img/logo.png" mode="aspectFill" class="phone-logo">
				</image>
				<view class="rowbox name">袋鼠会员通</view>
				<button type="primary" class="login-btn" open-type="getPhoneNumber"
					@getphonenumber="getPhoneNumber">绑定手机号</button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				agreeflag: false,
				phoneshow: false,
				avatarUrl: '',
				nickname: '',
			}
		},
		methods: {
			showNotice() {
				if (this.nickname == '') {
					uni.showToast({
						title: '请输入昵称',
						icon: 'none'
					})
				}
			},
			getPhoneNumber(e) {
				uni.showLoading({
					title: '加载中'
				})
				let data = {
					encryptedData: e.detail.encryptedData,
					iv: e.detail.iv,
					uid: uni.getStorageSync('puid')
				}
				this.$req.post('/shanghu/phoneJm', {
					encryptedData: e.detail.encryptedData,
					iv: e.detail.iv,
					uid: uni.getStorageSync('puid')
				}).then(res => {
					if (res.data.code == 0) {
						uni.setStorageSync('uid', uni.getStorageSync('puid'))
						uni.setStorageSync('userinfo', res.data.data)
						uni.navigateBack()
					} else {
						uni.hideLoading()
						uni.showModal({
							title: '授权手机号失败',
							content: '请稍后再试'
						})
					}
				})
			},
			getUserProfile() {
				if (this.agreeflag) {
					uni.showLoading({
						title: '正在登录'
					})
					uni.login({
						provider: 'weixin',
						success: (res) => {
							this.$req.post('/shanghu/userlogin', {
								code: res.code,
								// pid: ''
							}).then(res => {
								uni.setStorageSync('uid', res.data.data.id)
								uni.setStorageSync('userInfo', res.data.data)
								uni.hideLoading()
								uni.navigateBack()
								// this.phoneshow = true
							})
						},
						fail: (err) => {
							console.log('登录失败', err)
						}
					})
				} else {
					uni.showModal({
						title: '请阅读同意《用户协议》、《隐私协议》'
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.logo {
		margin-top: 70rpx;
		width: 150rpx;
		height: 150rpx;
		border-radius: 100rpx;
	}

	.name {
		margin-top: 20rpx;
	}

	.log-btn {
		width: 600rpx;
		border-radius: 100rpx;
		margin-top: 140rpx;
		height: 100rpx;
		color: #fff;
	}

	.no-log {
		height: 100rpx;
		width: 600rpx;
		border-radius: 100rpx;
		margin-top: 40rpx;
		font-size: 30rpx;
		color: #2e2e2f;
		border: #a2a2a2 solid 1px;
	}

	.radio-box {
		margin-top: 40rpx;
	}

	.loginfobox {
		width: 90%;
		margin-left: 5%;
		position: relative;
		padding: 40rpx 40rpx;
		border-bottom: #f2f6f9 solid 1px;
		font-size: 28rpx;

		input {
			text-align: right;
			font-size: 28rpx;
		}

		image {
			width: 70rpx;
			height: 70rpx;
			border-radius: 100rpx;
		}
	}

	.avatar-wrapper {
		width: 200rpx;
		height: 70rpx;
		position: absolute;
		right: 40rpx;
		opacity: 0;
	}

	.title {
		font-size: 28rpx;
		color: #000;
		font-weight: normal;
	}

	.slot-content {
		width: 500rpx;
		padding: 40rpx 0;
	}

	.login-btn {
		width: 400rpx;
		margin-top: 40rpx;
		background: #57bd6a;
	}

	.phone-logo {
		width: 100rpx;
		height: 100rpx;
		border-radius: 100rpx;
	}
</style>